package cn.jtfadmin.base.lang.config;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.Order;

/**
 * 静态的spring容器持有者
 *
 * @author jtf
 * @since 0.0.1
 */
@Configuration()
@Order(value = Integer.MIN_VALUE)
@Lazy(false)
public class ApplicationHolder implements ApplicationContextAware, DisposableBean {


    private static ApplicationContext applicationContext;

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        ApplicationHolder.applicationContext = applicationContext;
    }


    @Override
    public void destroy() throws Exception {
        ApplicationHolder.applicationContext = null;
    }

}
